/**************************************************************
  > File Name: 88.c
  > Author: LuoLiang
  > Mail: 1204553475@qq.com 
  > Created Time: 2022年02月11日 星期五 09时01分55秒
 **************************************************************/

#include <stdio.h>
#include <stdlib.h>

#define ASIZE 11
#define BSIZE 6

void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n)
{
	int aRight = m - 1;
	int bRight = n - 1;
	int pos = m + n - 1;
    	int cur;

	while (aRight >= 0 || bRight >= 0)
	{
		if (bRight == -1)
		{
			cur = nums1[aRight--];
		}
		else if (aRight == -1)
		{
			cur = nums2[bRight--];
		}
        else if (nums1[aRight] > nums2[bRight])
		{
			cur = nums1[aRight--];
		}
        else
        {
            cur = nums2[bRight--];
        }
		nums1[pos--] = cur;
	}
}


int main(int argc, char **argv)
{
	int a[ASIZE] = {1,2,3,5,6};
	int b[BSIZE] = {2,3,4,5,8,9};
	
	merge(a, ASIZE, 5, b, BSIZE, 6);
	
	for (int i = 0; i < ASIZE; i++)	
	{
		printf("%d ",a[i]);
	}

    exit(0);
}
